<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="query">
				<el-form-item>
					<el-input v-model="query.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="search">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="pageInfo.rows" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="name" label="名称" width="120" sortable>
			</el-table-column>
      <el-table-column prop="url" label="url" width="180" sortable>
      </el-table-column>
      <el-table-column prop="sn" label="标识" width="300" sortable>
      </el-table-column>
      <el-table-column prop="parent.name" label="父权限" width="180" sortable>
      </el-table-column>
      <el-table-column prop="descs" label="描述" width="120" sortable>
      </el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :page-size="query.pageSize"
          :total="pageInfo.total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>

	export default {
		data() {
			return {
				listLoading: false,
				sels: [],//列表选中列
        query:{
				  currentPage:1,
          pageSize:10,
          keyword:""
        },
        pageInfo:{
				  total:0,
          rows:[]
        }
			}
		},
		methods: {
      search(){
        // 将当前页的值改为1
        this.query.currentPage = 1;
        this.getPermissions();
      },
			handleCurrentChange(val) {
				// val 当前要跳转的页码
        this.query.currentPage = val;
        this.getPermissions();
			},
			//获取权限列表
      getPermissions() {
				  this.$http.post("/permission",this.query)
              .then(result => {
                  result = result.data;
                  console.log(result);
                  if(result.success){ // 判断后端操作是否成功
                    this.pageInfo = result.resultObj;
                  }else{
                    this.$message({
                      message: result.message,
                      type: 'error'
                    });
                  }
              })
              .catch(result => {
                this.$message({
                  message: '网络错误!',
                  type: 'error'
                });
              })
			},
		},
		mounted() {
		  // 页面一加载完毕,就要调用后端接口渲染列表
			this.getPermissions();
		}
	}

</script>

<style scoped>

</style>